FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y \
      sudo tmux emacs git gdb cmake build-essential net-tools psmisc \
      libssl-dev zlib1g-dev libkrb5-dev libkrb5-dbg

ARG UID=1000

# Create a non-root user account to run libssh.
RUN adduser attacker --disabled-password --uid $UID

# Grant the 'attacker' user sudo access. This is not used for the demo,
# but it is often handy for installing extra packages.
RUN adduser attacker sudo
RUN echo "attacker:x" | chpasswd
COPY home/ /home/attacker/
RUN chown -R attacker:attacker /home/attacker

# Switch over to the 'attacker' user, since root access is no longer required
USER attacker
WORKDIR /home/attacker

# Clone and build libssh v0.10.4
RUN git clone https://git.libssh.org/projects/libssh.git && \
    cd libssh && \
    git checkout e8322817a9e5aaef0698d779ddd467a209a85d85 && \
    git apply ~/diff.txt && \
    mkdir build && cd build && \
    cmake .. && \
    make -j $(nproc)

USER attacker
